const { envList } = require('../../envList.js');
Page({
  data:{
    swiperList:["cloud://cloud1-1gz9y3az8360d835.636c-cloud1-1gz9y3az8360d835-1307456793/075f4deff1a642c442db95df90ea80d.jpg","cloud://cloud1-1gz9y3az8360d835.636c-cloud1-1gz9y3az8360d835-1307456793/075f4deff1a642c442db95df90ea80d.jpg"],
    seTime:"",
    startTime:"2021-10-30",
    endTime:"",
    catesList:[{"src":"../../icons/1.png","msg":"日历","navsrc":"/pages/diary/diary"},{"src":"../../icons/2.png","msg":"打卡","navsrc":"/pages/editor/editor"},{"src":"../../icons/3.png","msg":"图库","navsrc":"/pages/diary/diary"},{"src":"../../icons/4.png","msg":"观影"},{"src":"../../icons/5.png","msg":"留言","navsrc":"/pages/diary/diary"},{"src":"../../icons/6.png","msg":"任务","navsrc":"/pages/diary/diary"},{"src":"../../icons/7.png","msg":"商城","navsrc":"/pages/diary/diary"},{"src":"../../icons/8.png","msg":"待续","navsrc":"/pages/diary/diary"}]

  },
  checkDate: function(startTime,endTime) {
    //日期格式化
    var start_date = new Date(startTime.replace(/-/g, "/"));
    var end_date = new Date(endTime.replace(/-/g, "/"));
    //转成毫秒数，两个日期相减
    var ms = end_date.getTime() - start_date.getTime();
    //转换成天数
    var day = parseInt(ms / (1000 * 60 * 60 * 24));
    //do something
    console.log("day = ", day);
    this.setData({
      seTime:day+1
    })
},

  formatTime: function(date) {
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let hour = date.getHours();
    let minute = date.getMinutes();
    let second = date.getSeconds();
    return [year, month, day].map(this.formatNumber).join('-');
  },

  formatNumber: function(n) {
    n = n.toString();
    return n[1] ? n : '0' + n;
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var currenTime= this.formatTime(new Date());
    this.checkDate(this.data.startTime,currenTime)
    this.setData({
      endTime:currenTime
    })
  },

})
